package il.ac.tau.cvws.scrabblesidekick.server.util.file;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.imageio.ImageIO;
import javax.xml.bind.DatatypeConverter;

public class ConversionUtil
{
	public static BufferedImage convertStringToImage(String imageStr)
	{
		byte[] imageBytes = DatatypeConverter.parseBase64Binary(imageStr);
		
		InputStream in = null;
		BufferedImage image = null;
				
		try
		{
			in = new ByteArrayInputStream(imageBytes);
			image = ImageIO.read(in);	
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if (in != null)
				{
					in.close();
				}
			}
			catch (IOException e) {}
		}
		
		return image;
	}
}
